package ctrip;

import java.util.Scanner;

public class SellStock {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String allNumber;
		String[] numbers;
		int[] num;
		while(scanner.hasNext()){
			allNumber = scanner.nextLine();
			numbers = allNumber.split(",");
			num = new int[numbers.length];
			for (int i = 0; i < numbers.length; i++) {
				num[i] = Integer.parseInt(numbers[i]);
			}
			maxProfit(num);
		}
		scanner.close();
	}

	// just can buy and sell once
	public static int maxProfit(int[] num) {
		if (num == null || num.length <= 0) {
			System.err.println("the wrong input");
			return 0;
		}
		int leftMin = num[0]; // 在i之前数组中最小的元素
		int maxProfit = 0; // 最大收益
		for (int i = 1; i < num.length; i++) {
			if (num[i] > leftMin) {
				maxProfit = Math.max(maxProfit, num[i] - leftMin);
			} else if (num[i] < leftMin) {
				leftMin = num[i];
			}
		}
		System.out.println(maxProfit);
		return maxProfit;
	}
}
